package com.zpark.it.service.impl;

import com.zpark.it.clients.UserClient;
import com.zpark.it.controller.UserController;
import com.zpark.it.param.CartListParam;
import com.zpark.it.param.PageParam;
import com.zpark.it.pojo.User;
import com.zpark.it.service.UserService;
import com.zpark.it.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @Title: UserServiceImpl
 * @Author Charles
 * @Package com.zpark.it.service.impl
 * @Date 2023/7/27 10:17
 */
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserClient userClient;
    /**
     * 用户的展示业务方法
     *
     * @param pageParam
     * @return
     */
    @Cacheable(value = "list.user",key = "#pageParam.currentPage+'-'+#pageParam.getPageSize()")
    @Override
    public R userList(PageParam pageParam) {

        R r = userClient.adminListPage(pageParam);
        return r;
    }

    /**
     * 删除用户数据
     *
     * @param param
     * @return
     */
    @CacheEvict(value = "list.user",allEntries = true) //清空所有缓存
    @Override
    public R userRemove(CartListParam param) {

        R r = userClient.adminRemove(param);
        return r;
    }

    /**
     * 根据用户对象，修改用户信息
     *
     * @param user
     * @return
     */
    @Override
    @CacheEvict(value = "list.user",allEntries = true) //清空所有缓存
    public R userUpdate(User user) {

        R r = userClient.adminUpdate(user);
        return r;
    }

    /**
     * 添加用户信息
     *
     * @param user
     * @return
     */
    @Override
    @CacheEvict(value = "list.user",allEntries = true) //清空所有缓存
    public R save(User user) {
        R r = userClient.adminSave(user);
        return r;
    }
}
